package org.htmlparser.scanners;

import java.util.Vector;
import org.htmlparser.Attribute;
import org.htmlparser.Node;
import org.htmlparser.NodeFactory;
import org.htmlparser.Tag;
import org.htmlparser.lexer.Lexer;
import org.htmlparser.tags.ScriptTag;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;

public class ScriptScanner extends CompositeTagScanner
{
  public static boolean STRICT = true;

  public Tag scan(Tag paramTag, Lexer paramLexer, NodeList paramNodeList)
    throws ParserException
  {
    boolean bool;
    if (paramTag instanceof ScriptTag)
    {
      String str1 = ((ScriptTag)paramTag).getLanguage();
      if ((str1 != null) && (((str1.equalsIgnoreCase("JScript.Encode")) || (str1.equalsIgnoreCase("VBScript.Encode")))))
      {
        String str2 = ScriptDecoder.Decode(paramLexer.getPage(), paramLexer.getCursor());
        ((ScriptTag)paramTag).setScriptCode(str2);
      }
    }
    if (!(STRICT))
      bool = true;
    while (true)
    {
      Node localNode = paramLexer.parseCDATA(bool);
      int i = paramLexer.getPosition();
      Object localObject = paramLexer.nextNode(false);
      if ((localObject != null) && (((!(localObject instanceof Tag)) || (!(((Tag)localObject).isEndTag())) || (!(((Tag)localObject).getTagName().equals(paramTag.getIds()[0]))))))
      {
        paramLexer.setPosition(i);
        localObject = null;
      }
      if (localObject == null)
      {
        Attribute localAttribute = new Attribute("/script", null);
        Vector localVector = new Vector();
        localVector.addElement(localAttribute);
        localObject = paramLexer.getNodeFactory().createTagNode(paramLexer.getPage(), i, i, localVector);
      }
      paramTag.setEndTag((Tag)localObject);
      if (localNode != null)
      {
        paramTag.setChildren(new NodeList(localNode));
        localNode.setParent(paramTag);
      }
      ((Node)localObject).setParent(paramTag);
      paramTag.doSemanticAction();
      return paramTag;
      bool = false;
    }
  }
}